/**
 * JAVACC DEMO 1.0
 */
package com.apache.client;

import com.apache.api.vo.ResultEntity;
import com.apache.tools.ConfigUtil;
import com.apache.uct.common.ToolsUtil;

import java.util.Map;

/**
 * description:  工作流系统特殊操作处理类
 *
 * @author ius 创建时间：2016-4-3
 */
public class FlowCoreClient {

    private static String sysPass = ConfigUtil.getInstance().interfacePass();

    /**
     * 根据权限Id，是否跨部门，部门id获取用户(actId,deptcross,deptId)
     */
    public static String getUsersStr(Map<String, Object> map) {
        map.put("sysPass", sysPass);
        map.put("methodType", "getUsersStr");
        String result = "";
        ResultEntity root = UctProtoclClient.getInstance().doService("uctService", "flowCore", map);
        if (!ToolsUtil.isEmpty(root.getEntity())) {
            result = getXmlForUsers(root.getResult(), root.getMessage(),
                    String.valueOf(root.getEntity()));
        } else {
            result = getXmlForUsers("false", root.getMessage(), "");
        }
        return result;
    }

    /**
     * description:  远程根据系统获取该系统下的权限树(fatherId,actId)
     */
    public static String getActTree(Map<String, Object> map) {
        map.put("sysPass", sysPass);
        map.put("methodType", "getActTree");
        String result = "";
        ResultEntity root = UctProtoclClient.getInstance().doService("uctService", "flowCore", map);
        if (!ToolsUtil.isEmpty(root.getEntity())) {
            result = getXmlForActTree(root.getResult(), root.getMessage(),
                    String.valueOf(root.getEntity()));
        } else {
            result = getXmlForActTree("false", root.getMessage(), "");
        }
        return result;
    }

    private static String getXmlForUsers(String result, String errmsg, String users) {
        StringBuffer XmlStr = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><root>");
        XmlStr.append(
                "<result>" + result + "</result><errmsg>" + errmsg + "</errmsg><users>" + users
                        + "</users>");
        XmlStr.append("</root>");
        return XmlStr.toString();
    }

    private static String getXmlForActTree(String result, String errmsg, String jsonInfo) {
        StringBuffer XmlStr = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><root>");
        XmlStr.append("<result>" + result + "</result><errmsg>" + errmsg + "</errmsg><jsonInfo>"
                + jsonInfo + "</jsonInfo>");
        XmlStr.append("</root>");
        return XmlStr.toString();
    }
}
